package io.github.talelin.latticy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import io.github.talelin.latticy.mapper.GoodsMapper;
import io.github.talelin.latticy.mapper.WarehouseStockMapper;
import io.github.talelin.latticy.model.ztyDO.ShopStockDO;
import io.github.talelin.latticy.model.ztyDO.WarehouseStockDO;
import io.github.talelin.latticy.pojo.Goods;
import io.github.talelin.latticy.pojo.ShopStock;
import io.github.talelin.latticy.pojo.WarehouseStock;
import io.github.talelin.latticy.service.WarehouseStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZTY
 * @since 2021-04-15
 */
@Service
public class WarehouseStockServiceImpl extends ServiceImpl<WarehouseStockMapper, WarehouseStock> implements WarehouseStockService {

    @Autowired
    GoodsMapper goodsMapper;

    @Override
    public List<WarehouseStockDO> selectAll() {
        List<WarehouseStockDO> warehouseStockDOs = new ArrayList<>();
        List<WarehouseStock> warehouseStocks = baseMapper.selectList(null);
        List<Goods> goods = goodsMapper.selectList(null);
        for (WarehouseStock warehouseStock : warehouseStocks) {
            WarehouseStockDO warehouseStockDO = new WarehouseStockDO();
            for (Goods good : goods) {
                if(good.getGoodsId().equals(warehouseStock.getGoodsId())){
                    warehouseStockDO.setGoodsName(good.getGoodsName());
                    warehouseStockDO.setGoodsPrice(good.getGoodsPrice());
                    warehouseStockDO.setGoodsId(good.getGoodsId());
                    warehouseStockDO.setInputPrice(good.getInputPrice());
                    break;
                }
            }
            warehouseStockDO.setStockValue(warehouseStock.getStockValue());
            warehouseStockDO.setWarehouseStockId(warehouseStock.getWarehouseStockId());
            warehouseStockDOs.add(warehouseStockDO);
        }
        return warehouseStockDOs;
    }
}
